package cn.sixmillions.wiki.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * @description: 基础Entity：创建人、创建时间、更新人、更新时间
 * @author: sixmillions
 * @since: 2021/06/04
 **/
public class BaseEntity<T extends Model> extends Model {
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty("创建人")
    @TableField(value = "created_by", fill = FieldFill.INSERT)
    private String createdBy;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("创建时间")
    @TableField(value = "created_date", fill = FieldFill.INSERT)
    private LocalDateTime createdDate;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty("更新人")
    @TableField(value = "last_modified_by", fill = FieldFill.INSERT_UPDATE)
    private String lastModifiedBy;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("更新时间")
    @TableField(value = "last_modified_date", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime lastModifiedDate;

    public BaseEntity() {
    }

    public String getCreatedBy() {
        return this.createdBy;
    }

    public LocalDateTime getCreatedDate() {
        return this.createdDate;
    }

    public String getLastModifiedBy() {
        return this.lastModifiedBy;
    }

    public LocalDateTime getLastModifiedDate() {
        return this.lastModifiedDate;
    }

    public void setCreatedBy(final String createdBy) {
        this.createdBy = createdBy;
    }

    public void setCreatedDate(final LocalDateTime createdDate) {
        this.createdDate = createdDate;
    }

    public void setLastModifiedBy(final String lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    public void setLastModifiedDate(final LocalDateTime lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BaseEntity)) {
            return false;
        } else {
            BaseEntity<?> other = (BaseEntity) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59:
                {
                    Object this$createdBy = this.getCreatedBy();
                    Object other$createdBy = other.getCreatedBy();
                    if (this$createdBy == null) {
                        if (other$createdBy == null) {
                            break label59;
                        }
                    } else if (this$createdBy.equals(other$createdBy)) {
                        break label59;
                    }

                    return false;
                }

                Object this$createdDate = this.getCreatedDate();
                Object other$createdDate = other.getCreatedDate();
                if (this$createdDate == null) {
                    if (other$createdDate != null) {
                        return false;
                    }
                } else if (!this$createdDate.equals(other$createdDate)) {
                    return false;
                }

                Object this$lastModifiedBy = this.getLastModifiedBy();
                Object other$lastModifiedBy = other.getLastModifiedBy();
                if (this$lastModifiedBy == null) {
                    if (other$lastModifiedBy != null) {
                        return false;
                    }
                } else if (!this$lastModifiedBy.equals(other$lastModifiedBy)) {
                    return false;
                }

                Object this$lastModifiedDate = this.getLastModifiedDate();
                Object other$lastModifiedDate = other.getLastModifiedDate();
                if (this$lastModifiedDate == null) {
                    if (other$lastModifiedDate != null) {
                        return false;
                    }
                } else if (!this$lastModifiedDate.equals(other$lastModifiedDate)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof BaseEntity;
    }

    public int hashCode() {
        int result = 1;
        Object $createdBy = this.getCreatedBy();
        result = result * 59 + ($createdBy == null ? 43 : $createdBy.hashCode());
        Object $createdDate = this.getCreatedDate();
        result = result * 59 + ($createdDate == null ? 43 : $createdDate.hashCode());
        Object $lastModifiedBy = this.getLastModifiedBy();
        result = result * 59 + ($lastModifiedBy == null ? 43 : $lastModifiedBy.hashCode());
        Object $lastModifiedDate = this.getLastModifiedDate();
        result = result * 59 + ($lastModifiedDate == null ? 43 : $lastModifiedDate.hashCode());
        return result;
    }

    public String toString() {
        return "BaseEntity(createdBy=" + this.getCreatedBy() + ", createdDate=" + this.getCreatedDate() + ", lastModifiedBy=" + this.getLastModifiedBy() + ", lastModifiedDate=" + this.getLastModifiedDate() + ")";
    }
}
